package com.yulong.web.server.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yulong.model.pojo.UmsMenu;
import com.yulong.model.pojo.UmsPermission;
import com.yulong.model.pojo.UmsResource;
import com.yulong.model.pojo.UmsRole;
import com.yulong.web.mapper.UmsRoleMapper;
import com.yulong.web.server.UmsRoleServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class UmsRoleServerImpl implements UmsRoleServer {

    @Autowired
    private UmsRoleMapper umsRoleMapper;

    @Override
    public int create(UmsRole role) {
        role.setCreateTime(new Date());
        role.setAdminCount(0);
        role.setSort(0);
        return umsRoleMapper.insertRole(role);
    }

    @Override
    public int update(Long id, UmsRole role) {
        role.setId(id);
        role.setCreateTime(new Date());
        int i = umsRoleMapper.updateRole(role);
        return i;
    }

    @Override
    public int delete(List<Long> ids) {
        int i = umsRoleMapper.delete(ids);
        return i;
    }

    @Override
    public List<UmsPermission> getPermissionList(Long roleId) {
        return null;
    }

    @Override
    public int updatePermission(Long roleId, List<Long> permissionIds) {
        return 0;
    }

    @Override
    public List<UmsRole> list() {
        List<UmsRole>  umsRoles= umsRoleMapper.selectAll();
        return umsRoles;
    }



    @Override
    public PageInfo<UmsRole> list(String keyword, Integer pageSize, Integer pageNum) {
        PageHelper.startPage(pageSize,pageNum);
        PageInfo<UmsRole> umsRolePageInfo = new PageInfo<>(umsRoleMapper.queryByName(keyword));
        return umsRolePageInfo;
    }

    @Override
    public List<UmsMenu> getMenuList(Long adminId) {
        return null;
    }

    @Override
    public List<UmsMenu> listMenu(Long roleId) {
        return umsRoleMapper.getlistMenu(roleId);
    }

    @Override
    public List<UmsResource> listResource(Long roleId) {
        List<UmsResource> umsResources = umsRoleMapper.listResource(roleId);
        return umsResources;
    }

    @Override
    public int allocMenu(Long roleId, List<Long> menuIds) {
        return 0;
    }

    @Override
    public int allocResource(Long roleId, List<Long> resourceIds) {
        return 0;
    }
}
